package com.lemon.smartsafety.http;

import android.app.Activity;
import android.content.Intent;

import com.lemon.smartsafety.result.BaseMode;
import com.lemon.smartsafetynew.ui.activity.SplashActivity;
import com.lemon.smartsafety.utils.CommonUtil;
import com.lemon.smartsafety.utils.SPUtils;
import com.lemon.smartsafety.utils.app.ToastUtils;


/**
 * 项目名称：exec_law
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/6/12 10:07
 * 修改人：Fargo
 * 修改时间：2016/6/12 10:07
 * 修改备注：
 */
public class HttpBack {




    public static boolean httpBackForMode(Activity activity, BaseMode baseMode) {

        try {
            if (CommonUtil.objIsEmpty(baseMode)) {
                return false;
            }

            if (baseMode.getCode().equals("1000") || baseMode.getCode().equals("1003") ) {
                return true;
            } else {

                if(baseMode.getCode().equals("1004")){
                    ToastUtils.toastMsg(baseMode.getMsg());
                }else if (baseMode.getCode().equals("1001") || baseMode.getCode().equals("1002")) {
                    ToastUtils.showButtomToast("身份已过期，请重新登录");
                    SPUtils.clear(activity.getApplicationContext());

                    activity.startActivity(new Intent(activity, SplashActivity.class)
                            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra("strType", "3"));
                }
                return false;
            }

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }


    }


    public static boolean httpBackErrorMsg(BaseMode baseMode) {

        try {
            if (CommonUtil.objIsEmpty(baseMode)) {
                return false;
            }
            if (!baseMode.getCode().equals("1001")
                    && !baseMode.getCode().equals("1002")
                    && !baseMode.getCode().equals("1003")
                    && !baseMode.getCode().equals("1004")) {
                ToastUtils.toastMsg(baseMode.getMsg());
            }

            return false;

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
     }

    public static boolean httpBackError(BaseMode baseMode) {

        try {
            if (CommonUtil.objIsEmpty(baseMode)) {
                return false;
            }
            if (!baseMode.getCode().equals("1000"))
            {
                return false;
            }

        /*    if(baseMode.getCode().equals("1004")){
                ToastUtils.toastMsg("不能重复提交");
            }*/

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }




}
